package cn.tedu.csmall.product.service.impl;

import cn.tedu.csmall.commons.exception.ServiceException;
import cn.tedu.csmall.commons.pojo.vo.PageData;
import cn.tedu.csmall.commons.util.PageDataConverter;
import cn.tedu.csmall.commons.web.ServiceCode;
import cn.tedu.csmall.product.mapper.AlbumMapper;
import cn.tedu.csmall.product.mapper.PictureMapper;
import cn.tedu.csmall.product.mapper.SKUMapper;
import cn.tedu.csmall.product.mapper.SPUMapper;
import cn.tedu.csmall.product.pojo.entity.Album;
import cn.tedu.csmall.product.pojo.entity.Picture;
import cn.tedu.csmall.product.pojo.entity.SKU;
import cn.tedu.csmall.product.pojo.entity.SPU;
import cn.tedu.csmall.product.pojo.param.AlbumInsertParam;
import cn.tedu.csmall.product.pojo.param.AlbumUpdateInfoParam;
import cn.tedu.csmall.product.pojo.param.PictureInsertParam;
import cn.tedu.csmall.product.pojo.vo.AlbumListVO;
import cn.tedu.csmall.product.pojo.vo.AlbumStandardVO;
import cn.tedu.csmall.product.pojo.vo.PictureListVO;
import cn.tedu.csmall.product.service.AlbumService;
import cn.tedu.csmall.product.service.PictureService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class PictureServiceImpl implements PictureService {

    @Autowired
    PictureMapper mapper;
    @Override
    public void insert(PictureInsertParam pictureInsertParam) {

        Picture picture = new Picture();
        BeanUtils.copyProperties(pictureInsertParam,picture);
        picture.setGmtCreate(LocalDateTime.now());
        picture.setGmtModified(LocalDateTime.now());
        int row = mapper.insert(picture);
        if(row !=1){
            String message="添加管理员失败，服务器忙，请稍后再试!";
            log.warn(message);
            throw new ServiceException(message, ServiceCode.ERR_INSERT);
        }
    }

    @Override
    public List<PictureListVO> listByAlbumId(Long id) {
        List<PictureListVO> pictureListVO = mapper.listByAlbumId(id);
        return pictureListVO;
    }
}
